package smu.KYBank.test;

import smu.KYBank.DBHandler;
import smu.KYBank.KYBdeposit;
import android.database.Cursor;
import android.test.ActivityInstrumentationTestCase2;
import android.test.TouchUtils;
import android.view.KeyEvent;
import android.widget.EditText;
import android.widget.TextView;

public class KYBdepositTest2 extends
		ActivityInstrumentationTestCase2<KYBdeposit> {
	private KYBdeposit mActivity;
	EditText d_money;
	TextView bal;
	String login_id = "rul", balance;

	public KYBdepositTest2() {
		super("smu.KYBank", KYBdeposit.class);
	}
		
	protected void setUp() throws Exception {
		super.setUp();
		
		mActivity = this.getActivity();
		
		bal = (TextView) mActivity.findViewById(smu.KYBank.R.id.d_bal);

		d_money = (EditText) mActivity.findViewById(smu.KYBank.R.id.d_money);
		try {
			runTestOnUiThread(new Runnable() {
				
				public void run() {
					// TODO Auto-generated method stub
					DBHandler dbhandler = DBHandler.open(mActivity);
					Cursor cursor = dbhandler.select_id(login_id + "	");
					if (cursor.moveToFirst()) {
						do {
							balance = cursor.getString(cursor.getColumnIndex("balance"));
							bal = (TextView) mActivity.findViewById(smu.KYBank.R.id.d_bal);
							bal.setText(balance);
						} while (cursor.moveToNext());
					}
					dbhandler.close();
				}
			});
		} catch (Throwable e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public void testDeposit() {
		TouchUtils.tapView(this, d_money);
		sendKeys(KeyEvent.KEYCODE_1, KeyEvent.KEYCODE_0, KeyEvent.KEYCODE_0, KeyEvent.KEYCODE_0, KeyEvent.KEYCODE_0);

		assertEquals(10450, mActivity.deposit(login_id));
	}

}
